package com.situ.hospital.department.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.situ.hospital.department.dao.IDepartmentDao;
import com.situ.hospital.department.dao.impl.DepartmentDaoImpl;
import com.situ.hospital.department.model.DepartmentModel;

public class DepartmentService {
	private IDepartmentDao dd=new DepartmentDaoImpl();
	
	public List<DepartmentModel> select(DepartmentModel department) throws SQLException {
		String name=department.getDepartmentName();
		department.setDepartmentName(name==null?"%%":"%"+name+"%");
		String address=department.getDepartmentAddress();
		department.setDepartmentAddress(address==null?"%%":"%"+address+"%");
		department.setId(1);
		return dd.selectAll(department);
	}

	public Integer add(DepartmentModel department) throws SQLException {
		DepartmentModel dm=new DepartmentModel();
		dm.setDepartmentName(department.getDepartmentName());
		DepartmentModel dm1=dd.selectModel(dm);
		return dm1==null?dd.insert(department):3;
	}

	public Integer del(DepartmentModel department) throws SQLException {
		return dd.deleteByName(department);
	}

	public Map<String,Object> selectModel(DepartmentModel Department) throws SQLException {
		Map<String,Object> map=new HashMap<>();
		map.put("selectmodel", dd.selectModel(Department));
		return map;
	}

	public Integer update(DepartmentModel upddepartment) throws SQLException {
		return dd.updateByName(upddepartment);
	}

	public int selectCount(DepartmentModel department) throws SQLException {
		DepartmentModel dm=new DepartmentModel(); 
		String name=department.getDepartmentName();
		dm.setDepartmentName(name==null?"%%":"%"+name+"%");
		String address=department.getDepartmentAddress();
		dm.setDepartmentAddress(address==null?"%%":"%"+address+"%");
		dm.setId(1);
		return dd.selectCount(dm);
	}
	
}
